//
// Created by ChenYulu on 2017/4/30.
//

#ifndef LAB3_QUEUE_H
#define LAB3_QUEUE_H

template<typename T>
struct Node {
  T value;
  Node<T> *next;
};

template<typename T>
class Queue {
 public:
  Queue();
  ~Queue();

  bool isEmpty();
  int size();
  bool pop();
  void push(T t);

 private:
  Node<T> *phead;
  Node<T> *pend;
  int count;

};

template<typename T>
Queue<T>::Queue() {
  phead = new Node<T>();
  pend = phead;
  count = 0;
}

template<typename T>
Queue<T>::~Queue() {
  while (phead->next != nullptr) {
    Node<T> *pnode = phead;
    phead = phead->next;
  }
}

template<typename T>
bool Queue<T>::isEmpty() {
  return count == 0;
}

template<typename T>
bool Queue<T>::pop() {
  if (count == 0) {
    return false;
  }
  Node<T> *pnode = phead->next;
  phead->next = phead->next->next;
  delete pnode;
  count--;
  return true;
}

#endif //LAB3_QUEUE_H
